
package dao;

import java.util.List;
import javax.persistence.EntityManager;
import model.Pessoa;
import java.util.Iterator;


public class DaoPessoa extends Dao{
    public Pessoa login(String usuario, String senha){
        Pessoa pessoa = null;
        EntityManager em = getEntityManager();
        Iterator<Pessoa> it = em.createQuery("select p from Pessoa p where p.usuario = :usuario and p.senha = :senha").
                    setParameter("usuario", usuario).
                    setParameter("senha", senha).
                    getResultList().iterator();
        if (it.hasNext())
            pessoa = it.next();
        
        return pessoa;
    }

    @Override
    public List listarTodos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object buscarPorId(Long id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    

    @Override
    public void inserir(Object object) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void atualizar(Object object) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void excluir(Object object) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    public boolean buscarPorLogin(String login){
        boolean retorno = false;
        EntityManager em = getEntityManager();
        List objs = em.createQuery("select a from Pessoa a where a.usuario = '"+login+"'").getResultList();
        if (!objs.isEmpty()){
            retorno = true;
        }
        return retorno;        
    }
    
    
}
